package com.dyb.recuitment.controller;


import com.dyb.recuitment.common.Result;
import com.dyb.recuitment.entity.JobComment;
import com.dyb.recuitment.entity.JobLike;
import com.dyb.recuitment.service.IJobCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 职位评论表 前端控制器
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-22
 */
@RestController
@Api(tags = "职位评论表(JobComment)")
@RequestMapping("/job_comment")
public class JobCommentController {

    @Autowired
    private IJobCommentService jobCommentService;

    @ApiOperation(value = "添加职位评论", notes = "通过用户ID、职位ID添加职位评论 " + "{\"userId\":1,\"jobId\":1,\"content\":\"\"}")
    @ApiImplicitParam(name = "jobComment", value = "JobComment类")
    @PostMapping("/add")
    public Object add(@RequestBody JobComment jobComment) {
        Object data = null;
        try {
            data = jobCommentService.add(jobComment);
//            userLogService.add(new UserLog(shield.getUserId(), "添加职位评论"));
            if (data == null || (int) data == 0) {
                return Result.warning(data, "添加失败!");
            }
            return Result.success(data, "添加成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "删除职位评论", notes = "通过ID删除职位评论 " + "{\"id\":1}")
    @ApiImplicitParam(name = "jobComment", value = "JobComment类")
    @PostMapping("/delete")
    public Object delete(@RequestBody JobComment jobComment) {
        Object data = null;
        try {
            data = jobCommentService.delete(jobComment);
//            userLogService.add(new UserLog(shield.getUserId(), "取消收藏"));
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "删除失败!");
            }
            return Result.success(data, "删除成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "查询职位评论", notes = "按条件查询职位评论 {\"userId\":1}")
    @ApiImplicitParam(name = "jobComment", value = "JobComment类")
    @PostMapping("/selectByJobComment")
    public Object selectByJobComment(@RequestBody JobComment jobComment) {
        Object data = null;
        try {
            data = jobCommentService.selectByJobComment(jobComment);
//            userLogService.add(new UserLog(shield.getUserId(), "查询职位评论"));
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "暂未发表评论!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "查询所有职位评论", notes = "查询所有职位评论")
    @GetMapping("/selectAllJobComment")
    public Object selectAllJobComment() {
        Object data = null;
        try {
            data = jobCommentService.selectAllJobComment();
//            userLogService.add(new UserLog(shield.getUserId(), "查询所有职位评论"));
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "职位评论表为空");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

}
